package com.lavegue.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.lavegue.common.BaseHibernateDao;
import com.lavegue.common.Page;
import com.lavegue.dao.CommentDao;
import com.lavegue.model.BisGroup;
import com.lavegue.model.Comment;

/**
 * author: luoweibin date:2010-10-29 description:
 * 
 */
public class CommentDaoImpl extends BaseHibernateDao<Comment, Integer> implements CommentDao {

	public CommentDaoImpl() {
		super(Comment.class);
	}

	public List<Comment> findCommentsByType(int type) {
		String query = "from Comment where type=? order by commentTime desc";
		return this.getHibernateTemplate().find(query, type);
	}

	//根据类型和标题查询
	 public Page<Comment> getAllCommentByType(int pageNo,int pageSize,String title,int typeId)
	 {
		 List<Criterion> condition = new ArrayList<Criterion>();
			if(null != title && !title.trim().equals("")){
			   condition.add(Restrictions.like("title", title, MatchMode.ANYWHERE));
			}
			condition.add(Restrictions.eq("type", typeId));
		    Page<Comment> page =this.findPage(pageNo, pageSize, condition, Order.desc("id"));
			return page;
	 }
	
}
